from django.db import models


# # Create your models here.
# class UiCaseGroup(models):
#     pass
#
#
# class ApiCaseGroup(models):
#     pass
class ApiCaseModel(models.Model):
    name = models.CharField(max_length=50, unique=True)
    desc = models.CharField(max_length=100)


class ApiCase(models.Model):
    method_list = (
        ('GET', 'GET'),
        ('POST', 'POST'),
        ('HEAD', 'HEAD'),
        ('PUT', 'PUT'),
        ('DELETE', 'DELETE'),
        ('OPTIONS', 'OPTIONS'),
        ('CONNECT', 'CONNECT'),
        ('TRACH', 'TRACH'),
    )
    title = models.CharField(max_length=50, help_text='用例标题')
    desc = models.CharField(max_length=200, help_text='用例描述')
    host = models.CharField(max_length=50, null=True)
    port = models.IntegerField(null=True)
    path = models.CharField(max_length=50, null=True)
    method = models.CharField(max_length=8, choices=method_list, default='GET')
    para = models.JSONField()
    body = models.JSONField()
    result = models.CharField(max_length=50)
    model = models.ForeignKey(ApiCaseModel, on_delete=models.CASCADE)
    projectid = models.CharField(max_length=20, help_text='所属项目id', null=True)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)
    class Meta:
        db_table = 'ApiCase'

class UiCaseStep(models.Model):
    element = models.ForeignKey(to='elements.UIElementes', on_delete=models.PROTECT)
    action = models.ForeignKey(to='elements.UIAction', on_delete=models.PROTECT)
    attr = models.CharField(max_length=20, null=True, help_text='当校验时取元素的属性')
    value = models.CharField(max_length=50, null=True, help_text='输入值或者校验值')
    timeout = models.IntegerField(null=True)
    index = models.IntegerField(null=False)
    case_id = models.ForeignKey(to='testcase.UiCase', on_delete=models.CASCADE)
    class Meta:
        db_table = 'UICaseStep'


class UiCase(models.Model):
    title = models.CharField(max_length=50, help_text='用例标题')
    desc = models.CharField(max_length=200, help_text='用例描述')
    project_id = models.CharField(max_length=100, help_text='所属项目id;')
    class Meta:
        db_table = 'UICase'
